import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:hive_flutter/hive_flutter.dart';
import 'package:ichinesereader/constants.dart';
import 'package:ichinesereader/controller/cache.dart';
import 'package:ichinesereader/pages/teacher/reportsBasket.dart';
import 'package:ichinesereader/pages/teacher/reportsClass.dart';
import 'package:ichinesereader/pages/teacher/reportsQuizBook.dart';
// import 'package:ichinesereader/pages/teacher/reportsSkillBuilding.dart';
import 'package:ichinesereader/pages/teacher/reportsStudent.dart';
import 'package:ichinesereader/pages/teacher/reportsHomework.dart';
import 'package:ichinesereader/routes/routePages.dart';
import 'package:ichinesereader/themes/pageStyles.dart';
import 'package:ichinesereader/utils/log.dart';
import 'package:ichinesereader/widgets/buttons/floatingActionButtonsTeacherSwitchClass.dart';
import 'package:ichinesereader/widgets/layouts/appdrawerTeacher.dart';
import 'package:ichinesereader/widgets/layouts/customAppBar.dart';
import 'package:ichinesereader/widgets/sidebars/teacherSidebar.dart';
import '../../themes/appTheme.dart';

late TabController teacherReportsTabController;

class TeacherReportsHomePage extends StatefulWidget {
  static const String routeName = '/teacher/reports';

  @override
  State<TeacherReportsHomePage> createState() => _TeacherReportsHomePageState();
}

class _TeacherReportsHomePageState extends State<TeacherReportsHomePage>
    with SingleTickerProviderStateMixin {
  final box = Hive.box('appconfig');

  @override
  void initState() {
    teacherReportsTabController = TabController(vsync: this, length: 5);
    super.initState();
  }

  @override
  void dispose() {
    //Get.delete<ReportsController>();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    Log.debug('build Teacher Reports home Page');
    bool isTeacher = box.get(CacheManagerKey['nanhairole'].toString()) ==
        Constants.NanhaiRole_Teacher;
    final PageStyles _pageStyles = PageStyles();
    final isSmallScreen =
        MediaQuery.of(context).size.width < Constants.DefinedScreenSmallSize;
    final isMediumScreen =
        MediaQuery.of(context).size.width < Constants.DefinedScreenMediumSize;
    final isBigScreen =
        MediaQuery.of(context).size.width > Constants.DefinedScreenBigSize;
    int _selectedSidebarItem = RoutePages.teacherPageItems
        .indexWhere((page) => page.route == Get.currentRoute);

    return DefaultTabController(
      length: 5,
      child: Scaffold(
        drawer: isSmallScreen ? TeacherAppDrawer() : null,
        appBar: isSmallScreen ? CustomAppBar(title: 'Reports') : null,
        floatingActionButton: FloatingActionButtonsTeacherSwitchClass(),
        body: Container(
          decoration: _pageStyles.pageBoxDecoration(),
          child: Row(
            children: [
              Visibility(
                  visible: !isSmallScreen,
                  child: TeacherSidebarX(
                      selectedIndex: _selectedSidebarItem,
                      isBigScreen: isBigScreen)),
              Expanded(
                child: Container(
                  margin: _pageStyles.mainContainerPageEdgeInsets(),
                  child: Column(
                    children: [
                      Container(
                        padding: EdgeInsets.symmetric(vertical: 9.0),
                        //margin: EdgeInsets.only(bottom: 12.0),
                        decoration: BoxDecoration(
                          color: Get.isDarkMode
                              ? AppTheme.colors.darkTheme2
                              : Colors.black.withOpacity(0.1),
                          borderRadius: BorderRadius.circular(3.0),
                        ),
                        child: isMediumScreen
                            ? _pageStyles.buildTabBarWithContoller(
                                // ['C', 'S', 'B', 'H', 'Q', 'S'],
                                ['C', 'S', 'B', 'H', 'Q'],
                                teacherReportsTabController)
                            : _pageStyles.buildTabBarWithContoller([
                                'Class',
                                'Students',
                                'Basket',
                                'Homework',
                                'Quiz Books',
                                // 'Skill Building'
                              ], teacherReportsTabController),
                      ),
                      Expanded(
                        flex: 9,
                        child: Container(
                          child: isTeacher
                              ? TabBarView(
                                  controller: teacherReportsTabController,
                                  children: [
                                    TeacherReportsClass(),
                                    TeacherReportsStudent(showAppbar: false),
                                    TeacherReportsBasket(showAppbar: false),
                                    TeacherReportsHomework(showAppbar: false),
                                    TeacherReportsQuizBook(),
                                    // TeacherReportSkillBuilding()
                                  ],
                                )
                              : Text(''),
                        ),
                      )
                    ],
                  ),
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
